package com.sinai.mshab.client.ui.aggregate;

import java.util.ArrayList;
import java.util.HashMap;

import com.sinai.mshab.client.ui.FormComponent;

/**
 * Keeps a registry that maps database field names to one or more
 * <code>QuestionComposite</code> objects.
 * 
 * @author Arthur Kalmenson
 */
public class ComponentRegistry {

	/**
	 * The <code>HashMap</code> that contains the registry.
	 */
	private static HashMap componentRegistry = new HashMap();

	/**
	 * Registers <code>question</code> using <code>field_name</code> as the
	 * key.
	 * 
	 * @param field_name
	 *            The database field name.
	 * @param question
	 *            The <code>QuestionComposite</code> to register.
	 */
	public static void add(String field_name, FormComponent question) {
		componentRegistry = Page.addToHashMap(field_name, question, componentRegistry);
	}

	/**
	 * Returns the <code>QuestionComposite</code> associated with the database
	 * field name, <code>field_name</code>.
	 * 
	 * @param field_name
	 *            The database field name.
	 * @return the arraylist containing composites associated with this field name
	 */
	public static ArrayList get(String field_name) {
		return (ArrayList) componentRegistry.get(field_name);
	}

	/**
	 * Resets all info in the regisry.
	 */
	public static void reset() {
		componentRegistry.clear();
	}
}
